<template>
  <view class="container">
    <div class="top-block">
      <div class="title">卡片信息</div>
      <div class="row">
        <div class="label">业务号码</div>
        <div class="value color">{{ info.business_code }}</div>
      </div>
      <div class="row">
        <div class="label">ICCID</div>
        <div class="value color">{{ info.iccid }}</div>
      </div>
    </div>

    <div class="list-block">
      <div class="title">选择加油包</div>

      <div class="item-wrap" v-for="(item, index) in packageList" :key="index" @tap="$app.goPage(`/pages/payInfo/index?cid=${id}&pid=${item.id}`)">
        <div class="row">
          <div class="font-l">{{ item.name }}</div>
          <div class="color">{{ (item.flow ? item.flow + 'MB' : '') + ' ' + (item.voice ? item.voice + '分钟' : '') }}</div>
        </div>
        <div class="line"></div>
        <div class="row">
          <!-- <div class="del">￥{{ item.meal.origin_price.toFixed(2) }}</div> -->
          <div>
            ￥<span class="font-xl color">{{ item.price.toFixed(2) }}</span>
          </div>
        </div>
      </div>
    </div>
  </view>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.query.id,
      info: {},
      packageList: [],
    };
  },
  created() {
    this.fetchData();
    this.fetchPackage();
  },
  methods: {
    async fetchPackage() {
      const res = await this.$app.http(`/package/list`, { isSale: true });
      this.packageList = res.data.list;
    },
    async fetchData() {
      const res = await this.$app.http(`/card/getInfo`, {
        id: this.id,
      });
      if (res.data.id) {
        this.info = res.data;
      } else {
        this.$app.toast('找不到卡片信息');
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@mixin row {
  display: flex;
  align-items: center;
  margin: 10rpx 5rpx;
  padding: 5rpx 10rpx;
}

.container {
  .color {
    color: $text-color-3;
  }

  .title {
    font-size: $font-l;
    margin: 20rpx 10rpx;
    padding: 0rpx 20rpx;
    line-height: 1;
    font-weight: 700;
    border-left: 8rpx solid $text-color-3;
  }

  .top-block {
    padding: 10rpx 20rpx;
    border-bottom: 20rpx solid #efefef;

    .row {
      @include row;

      .label {
        margin-right: 10rpx;
      }
    }
  }

  .list-block {
    padding: 10rpx 20rpx;

    .item-wrap {
      padding: 5rpx 10rpx;
      margin: 30rpx 10rpx;
      background-color: #fff;
      box-shadow: 0px 1px 8px rgba(#333, 0.3);
      border-radius: 15rpx;

      .row {
        justify-content: space-between;
        @include row;

        .del {
          color: $text-color-5;
          text-decoration: line-through;
        }
      }

      .line {
        width: 100%;
        height: 1px;
        background-color: #efefef;
      }
    }
  }
}
</style>
